/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLForEntities;

import Interfaces.AdminInterface;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import Entities.*;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Dries
 */
public class BLAdmin implements AdminInterface {
    
    private Connectie connectie;
    EntityManager em = null;
    EntityTransaction et = null;

    public BLAdmin() {
    }
    
    
   
  @Override
    public boolean insertLand(Land land, int continentId) {

            this.beginConnectie();
            
            Query q = em.createNamedQuery("Continent.getContinentById");
            q.setParameter("id", continentId);
            Continent continent = (Continent) q.getSingleResult();
            
            //Continent continent = new Continent();
           
            land.setContinent(continent);
            
            et = em.getTransaction();
            et.begin();
            em.persist(land);
            et.commit();

            return true;
       
    }
  
    @Override
    public List<Continent> continenten() {
        return em.createNamedQuery("Continent.getAllContinent").getResultList();
    }

    private void beginConnectie() {

        connectie = new Connectie();

        if (em == null) {
            em = connectie.getConnectie();
        }

    }
    
    
}
